package model.room;

import common.RoomTypes;
import model.booking.Booking;

import java.time.LocalDate;

/*
*用来统计在一天中同一类型的房间还剩多少个
 */
public class RoomCount {
    private RoomTypes roomTypes;
    private double price;
    private int count;
    public RoomCount(RoomTypes roomTypes, LocalDate startDate, LocalDate endDate) {
        this.roomTypes = roomTypes;
        this.count = getRoomTypesCount(roomTypes,startDate, endDate);
    }
    public RoomCount(RoomTypes roomTypes, double price, LocalDate startDate, LocalDate endDate) {
        this.roomTypes = roomTypes;
        this.price = price;
        this.count = getRoomTypesCount(roomTypes,startDate, endDate);
    }
    //剩余数量
    public int getRoomTypesCount(RoomTypes roomTypes,LocalDate startDate, LocalDate endDate) {
        int count = 0;
        for (Booking booking : Booking.getBookingList()) {
            if (booking.getCheckInTime().isBefore(endDate) && booking.getCheckOutTime().isAfter(startDate) && booking.getRoomTypes().equals(roomTypes)) {
                count++;
            }
        }
        int Roomcount = getRoomTypesCount(roomTypes);
        return Roomcount-count;
    }

    //一个类型的房间有多少个
    public int getRoomTypesCount(RoomTypes roomTypes) {
        int Roomcount = 0;
        for (Room room : Room.getRooms()) {
            if(room.getRoomTypes().equals(roomTypes)){
                Roomcount++;
            }
        }
        return Roomcount;
    }
    public RoomTypes getRoomTypes() {
        return roomTypes;
    }

    public void setRoomTypes(RoomTypes roomTypes) {
        this.roomTypes = roomTypes;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }
}
